package com.platform.utils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class DateUtil {
    public static void main(String[] args) {
        List<LocalDate> lastSevenDays = getLastSevenDays();

        // 打印最近七天的日期
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (LocalDate date : lastSevenDays) {
            String formattedDate = date.format(formatter);
            System.out.println(formattedDate);
        }
    }

    public static List<String> getDate(){
        List<LocalDate> lastSevenDays = getLastSevenDays();

        List<String> list = new ArrayList<>();

        // 打印最近七天的日期
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (LocalDate date : lastSevenDays) {
            String formattedDate = date.format(formatter);
            System.out.println(formattedDate);
            list.add(formattedDate);
        }
        return list;
    }

    public static List<LocalDate> getLastSevenDays() {
        LocalDate today = LocalDate.now();
        List<LocalDate> lastSevenDays = new ArrayList<>();

        for (int i = 6; i >= 0; i--) {
            LocalDate date = today.minusDays(i);
            lastSevenDays.add(date);
        }

        return lastSevenDays;
    }
}
